class MmStorage {
  private storage: Storage

  constructor(storage: Storage) {
    this.storage = storage
  }

  set(key: string, value: any): void {
    this.storage.setItem(key, JSON.stringify(value))
  }

  get(key: string): any {
    const value = this.storage.getItem(key)
    return value ? JSON.parse(value) : value
  }

  remove(key: string): void {
    this.storage.removeItem(key)
  }

  clear(): void {
    this.storage.clear()
  }
}

export default MmStorage

export const MmLocalStorage = new MmStorage(window.localStorage)
export const MmSessionStorage = new MmStorage(window.sessionStorage)
